package com.aya.copy.tools.action.setter;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class DefaultTypeHandlerFactory implements TypeHandlerFactory {
    private Map<String, TypeHandler> map = new HashMap<>();

    public DefaultTypeHandlerFactory() {
        buildSetterFactoryMap();
    }

    protected void buildSetterFactoryMap() {
        registerTypeHandler(Byte.class.getName(), new ByteTypeHandler());
        registerTypeHandler(Integer.class.getName(), new IntegerTypeHandler());
        registerTypeHandler(Short.class.getName(), new ShortTypeHandler());
        registerTypeHandler(Integer.class.getName(), new IntegerTypeHandler());
        registerTypeHandler(Long.class.getName(), new LongTypeHandler());

        registerTypeHandler(Float.class.getName(), new FloatTypeHandler());
        registerTypeHandler(Double.class.getName(), new DoubleTypeHandler());

        registerTypeHandler(String.class.getName(), new StringTypeHandler());

        registerTypeHandler(Date.class.getName(), new DateTypeHandler());
        registerTypeHandler(BigDecimal.class.getName(), new BigDecimalTypeHandler());
    }

    private void registerTypeHandler(String name, TypeHandler value) {
        map.put(name, value);
    }

    @Override
    public TypeHandler getTypeHandler(String name) {
        return map.get(name);
    }
}
